package cn.itcast.oa.base;

import java.lang.reflect.ParameterizedType;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.itcast.oa.service.DepartmentService;
import cn.itcast.oa.service.PrivilegeService;
import cn.itcast.oa.service.RoleService;
import cn.itcast.oa.service.UserService;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@Controller
@Scope("prototype")
public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T>{
	
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//===========model的支持==================//
	
	protected T model ;
	public T getModel() {
		return model;
	}
	private Class<T> clazz = null;

	public BaseAction() {
		// 使用反射技术得到T的真实类型
		ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass(); // 获取当前new的对象的 泛型的父类 类型
		this.clazz = (Class<T>) pt.getActualTypeArguments()[0]; // 获取第一个类型参数的真实类型
//		System.out.println("clazz ---> " + clazz);
		//通过反射创建model实例
		try {
			model = clazz.newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}
	
	
	//===========所有Service实例的声明 ==================//
	@Resource
	protected  DepartmentService departmentService ;
	@Resource
	protected RoleService roleService ; 
	@Resource
	protected UserService userService ; 
	@Resource
	protected PrivilegeService privilegeService ;
	
}
